<script type="text/javascript" src="/theme/default/resource/js/lib/masonry.min.js"></script>
<div id="pageContent" class="tshowPage">
    <div id="typeHeader" style="background-image: url('/theme/default/resource/img/header_blurbg_1.jpg');">
        <div class="w1100 mc">
            <h1 class="text-center">
               时尚秀
                <span>
                    在这里已有数千万的时尚秀，总有一款适合你
                </span>
            </h1>
        </div>
    </div>
    <div class="w1100 mc type-bar" style="width:1080px">
        <form action="?">
            <input type="text" value="{$q}" name="q" autocomplete="off" placeholder="请输入关键字...">
            <i class="iconfont icon-search_input"></i>
            <input type="hidden" value="{$t}" name="t">
            <input type="hidden" value="{$sort}" name="sort">
        </form>
        {foreach $type as $val}
        <div class="type-item">
            <span>{$val['name']}</span>
            {foreach $val['sub_menu'] as $v}
            <a class="type" data-id="{$v['id']}" href="{:url('tshow/index',['t'=>$v['id']])}?q={$q}">{$v['name']}</a>
            {/foreach}
        </div>
        {/foreach}
        <div class="type-item">
            <span>筛选</span>
            <a data-id="new" href="{:url('tshow/index',['s'=>'new'])}?q={$q}">最新发布</a>
            <a data-id="hot" href="{:url('tshow/index',['s'=>'hot'])}?q={$q}">精选推荐</a>
            <a data-id="fav" href="{:url('tshow/index',['s'=>'fav'])}?q={$q}">收藏最火</a>
        </div>
    </div>

    <div class="w1100 mc grid" style="width: 1200px;">
        {foreach $shop as $val}
        <div class="grid-item grid-1">
            <div class="works">
                <ul>
                    <li class="thumb">
                        <img width="100%" height="auto" src="{$val->thumb}" alt="">
                        <a href="{:url('index/works',['id'=>$val->id])}"></a>
                        <span class="clear">&nbsp;</span>
                    </li>
                    <li class="title">
                        <p>{$val->title}</p>
                    </li>
                    <li class="user-info">
                        <a href="">
                            <img class="img-cly" height="30" width="30" src="http://cdn.uehtml.com/201611/1479700031861.jpg" alt="">
                            <p>
                                <span class="nick-name">王小江</span> 发表于
                                <span class="date-time">2017-04-07 13:03</span>
                            </p>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
        {/foreach}
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("#footer").hide();
        var options =
            {
                srcNode: '.grid-item',             // grid items (class, node)
                margin: '25px',             // margin in pixel, default: 0px
                width: '200px',             // grid item width in pixel, default: 220px
                max_width: '',              // dynamic gird item width if specified, (pixel)
                resizable: true,            // re-layout if window resize
                transition: 'all 0.5s ease' // support transition for CSS3, default: all 0.5s ease
            }
        $('.grid').gridify(options);
        var typeId = "{$t}";
        if(typeId){
            typeId = typeId.substr(0,typeId.length-1);
            typeId = typeId.split(',');
            $.each(typeId,function (index) {
                $('a[data-id='+typeId[index]+']').addClass('active');
            });
        }

        var sort = '{$sort}'||'new';
        console.log(sort);
        $("a[data-id="+sort+"]").addClass('active');

        $(".type-item a").click(function () {
            $(this).siblings('a').removeClass('active');
            if($(this).hasClass('active')){
                $(this).removeClass('active');
            }else{
                $(this).addClass('active');
            }

            var typeId='';
            $(".type-item a.type").each(function (index) {
                if($(this).hasClass('active')){
                    typeId += $(this).attr('data-id')+",";
                }
            });

            $(".type-item a").each(function (index) {
                if($(this).hasClass('active')){
                    s = $(this).attr('data-id');
                }
            });

            $("input[name=t]").val(typeId);
            var q = $("input[name=q]").val();
            window.location.href = "{:url('tshow/index')}?t="+typeId+"&q="+q+"&sort="+s;
            return false;
        });

        //page.initFooter(); //底部导航重置

        /*var grid = $('.grid').masonry({
            itemSelector: '.grid-item',
            columnWidth: 220,
            isInitLayout: false
        });

        function onLayout() {
            page.initFooter(); //底部导航重置
        }
        grid.masonry('on','layoutComplete',onLayout);
        grid.masonry();*/
    });
</script>